Skip to main content
Version: 1.3.1

Text to Image API Documentation

Text Validation Endpoint

  • Method: POST
  • Path: https://api.kadal.ai/text-to-image/api/v1/text_validation
  • Summary: Validates input text for suitability in image generation.

Description

This endpoint verifies that the provided text is well-formed and interpretable, ensuring it can be processed effectively to generate a corresponding image.

Request

  • Content-Type: multipart/form-data

Payload

ParameterDescriptionData TypeIs Optional
input_textText corresponding to which an image needs to be generatedStringNo

Response

Success (200 OK)

{
"status_code": 200,
"message": "SUCCESS::Text Validation generated successfully",
"input_text": "Your input text result will appear here"
}

Usage

import requests

url = "https://api.kadal.ai/text-to-image/api/v1/text_validation"
token = "your_token_here"

headers = {
"accept": "application/json",
"Authorization": f"Bearer {token}",
"Content-Type": "application/x-www-form-urlencoded",
}

data = {
"input_text": """A paper craft art depicting a girl giving her cat a gentle hug. Both sit amidst potted plants, with the cat purring contentedly while the girl smiles. The scene is adorned with handcrafted paper flowers and leaves."""
}

response = requests.post(url, headers=headers, data=data)

Text to Image Generation Endpoint

  • Method: POST
  • Path: https://api.kadal.ai/text-to-image/api/v1/text_to_image
  • Summary: Generates images from text with configurable count and aspect ratio.

Description

This endpoint generates images from input text using a selected AI model, with options to set the number of images and aspect ratio.

Request

  • Content-Type: multipart/form-data

Payload

ParameterDescriptionData TypeConstraints / Allowed ValuesOptional
user_model_selectionAI model used for generationStringMust be one of: dall-e-3No
input_textInput text promptStringNon-empty; max length: 300 charsNo
number_of_imagesNumber of images to generateStringRange: 1–3No
aspect_ratioAspect Ratio of imagesStringMust be one of: 1:1, 16:9, 9:16No

Response:

{
"status_code": 200,
"message": "SUCCESS::Text to Image generated successfully",
"images_created": {
"image_url_1": "Your image_url will appear here",
"image_url_2": "Your image_url will appear here",
"image_url_3": "Your image_url will appear here"
}
}

Usage

import requests

url = "https://api.kadal.ai/text-to-image/api/v1/text_to_image"
token = "your_token_here"

headers = {
"accept": "application/json",
"Authorization": f"Bearer {token}",
"Content-Type": "application/x-www-form-urlencoded",
}

data = {
"user_model_selection": "dall-e-3",
"input_text": """A paper craft art depicting a girl giving her cat a gentle hug. Both sit amidst potted plants, with the cat purring contentedly while the girl smiles. The scene is adorned with handcrafted paper flowers and leaves.""",
"number_of_images": "3",
"aspect_ratio": "1:1",
}

response = requests.post(url, headers=headers, data=data)

Text to Image Generation Endpoint V2

  • Method: POST
  • Path: https://api.kadal.ai/text-to-image/api/v1/text_to_image_v2
  • Summary: Generates images from text with configurable count and aspect ratio.

Description

This endpoint generates images from input text using a selected AI model, with options to set the number of images and aspect ratio.

Request

  • Content-Type: application/json

Payload

ParameterDescriptionData TypeConstraints / Allowed ValuesOptional
providerAI Provider used for generationStringMust be one of: azure, vertexaiNo
model_nameModel used for generationStringmodel name of the modelNo
input_textPromptStringPrompt of the ImageNo
number_of_imagesNumber of ImagesIntegerRange: 1-4No
aspect_ratioAspect Ratio of imagesStringMust be one of: AUTO, SQUARE, LANDSCAPE, PORTRAITNo
base64_imagesBase64 of the imagesBoolMust be one of: true, falseYes (default false)

Response:

Response Json
{
"status_code": 200,
"message": "Images generated successfully",
"images_created": [
{
"Image_url": "https://learningmate.co/assets/aigenerated/tmp/{tenant_id}/{user_id}/xxxxx.png"
}
],
"text_generated": "Here's a car from the future! "
}

Usage

Example code for curl:

cURL
curl -X 'POST' \
'https://api.kadal.ai/text-to-image/api/v1/text_to_image_v2' \
-H 'accept: application/json' \
-H 'api-key: LM-xxxxx' \
-H 'Content-Type: application/json' \
-d '{
"provider": "vertexai",
"model_name": "gemini-2.5-flash-image",
"input_text": "a car from future",
"number_of_images": 1,
"aspect_ratio": "AUTO",
"base64_images": false
}'

Example code for Python:

Python
import requests
import json

lm_key = "LM-xxxxxxxx" # LM key from you profile

# Define the endpoint URL
url = 'https://api.kadal.ai/text-to-image/api/v1/text_to_image_v2'

# Set up the headers
headers = {
'accept': 'application/json',
'api-key': lm_key,
'Content-Type': 'application/json'
}

# Define the payload (the data you are sending)
data = {
"provider": "vertexai", # Provider
"model_name": "gemini-2.5-flash-image", # Model name
"input_text": "a car from future", # Prompt
"number_of_images": 1, # Number of Image (1-4)
"aspect_ratio": "AUTO", # Ratio: AUTO, SQUARE, LANDSCAPE, PORTRAIT
"base64_images": False # Base_64 of the Images
}

try:
# Make the POST request
response = requests.post(url, headers=headers, json=data)

# Check if the request was successful
response.raise_for_status()

# Parse and print the JSON response
result = response.json()
print(json.dumps(result, indent=4))

except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
except Exception as err:
print(f"An error occurred: {err}")